﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Reservi
{
    public partial class FrmMain : Form
    {
        //游戏对象说明
        private Game _game;

        public FrmMain()
        {
            InitializeComponent();
        }

        private void FrmMain_Load(object sender, EventArgs e)
        {
            //初始化游戏类
            _game = new Game();
        }

        private void GameArea_Paint(object sender, PaintEventArgs e)
        {
            if (_game != null)//游戏已初始化
            {
                _game.Draw(e.Graphics, this.GameArea.Size);
            }
        }

        private void GameArea_MouseDown(object sender, MouseEventArgs e)
        {
            if (_game != null)
            {
                //调用game鼠标点击处理程序
                Block block=_game.MouseDown(e.Location, this.GameArea.Size);
                //重绘游戏区域
                this.GameArea.Invalidate();
                //判断游戏输赢
                if (_game.IsGameOver() == 0)
                {
                    MessageBox.Show("黑方获胜 Game Over!");
                    _game = new Game();
                    this.GameArea.Invalidate();
                }
                else if (_game.IsGameOver() == 1)
                {
                    MessageBox.Show("白方获胜 Game Over!");
                    _game = new Game();
                    this.GameArea.Invalidate();
                }
                else if (_game.IsGameOver() == 2)
                {
                    MessageBox.Show("和棋 Game Over!");
                    _game = new Game();
                    this.GameArea.Invalidate();
                }
            }
        }

        private void btnStartGame_Click(object sender, EventArgs e)
        {
            //重置游戏
            _game = new Game();
            this.GameArea.Invalidate();
        }

        private void btnAboutMe_Click(object sender, EventArgs e)
        {
            FrmAboutMe frm = new FrmAboutMe();
            frm.ShowDialog();
        }
    }
}
